type DataGroup = {
  id: string;
  label: string;
};

export function generatorDataGroup(
  ...rest: string[]
): [DataGroup[], Record<string, string>] {
  if (!rest) {
    return [[], {}];
  }

  if (rest.length % 2 !== 0) {
    throw new Error("参数数量不匹配");
  }
  const list: DataGroup[] = [];
  const map: Record<string, string> = {};
  for (let i = 0; i < rest.length; i += 2) {
    const id = rest[i];
    const label = rest[i + 1];
    list.push({ id, label });
    Object.assign(map, { [id]: label });
  }
  return [list, map];
}

// 判断菜单是否有权限
export function getMenuAuth(
  vipInfo: any,
  currentLevel: number,
  isLogin: boolean
) {
  if (!isLogin) {
    return currentLevel === 0;
  }
  // 过期了
  if (new Date(vipInfo?.expire_time).getTime() < Date.now()) {
    return currentLevel === 0;
  }
  return vipInfo?.level >= currentLevel;
}

export function isVip(vipInfo: any) {
  return new Date(vipInfo?.expire_time).getTime() < Date.now()
    ? false
    : vipInfo?.level > 0;
}

// 生成随机数
export function randomId() {
  // const max = BigInt('9223372036854775807'); // 2^63 - 1
  const max = BigInt("100000000");
  return Math.floor(Math.random() * Number(max));
}
